Skip to content

User Entity Schema#406

Merged
artemdemo merged 5 commits intomainfrom
users-and-auth
Mar 23, 2026
Merged

User Entity Schema#406
artemdemo merged 5 commits intomainfrom
users-and-auth

Conversation

@artemdemo
Copy link
Contributor

@artemdemo artemdemo commented Mar 11, 2026

Note

Description

This PR adds local User entity support to the base44 dev server, replacing the previous behavior of proxying all /User requests to production. The current authenticated user is automatically seeded into an in-memory User collection on startup, and a new JWT-aware router handles CRUD operations for the User entity locally. Entity names are now normalized to lowercase for consistent lookup.

Related Issue

None

Type of Change

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)
  • Documentation update
  • Refactoring (no functional changes)
  • Other (please describe):

Changes Made

  • Added a dedicated entities-user-router.ts that handles GET /User/:id (including me), POST /User/, PUT /User/:id with JWT-based auth via a withAuth wrapper
  • Database.load() is now async and automatically seeds a User collection with the current authenticated user's info (from readAuth())
  • Added buildUserSchema() to merge built-in User fields (full_name, email) with any custom User entity schema, and validates that built-in fields are not overridden
  • Refactored entities.tsroutes/entities/entities-router.ts and removed the remoteProxy parameter (no longer needed for User routes)
  • Moved stripInternalFields utility to utils.ts and entity name normalization (.toLowerCase()) added to Database
  • Changed Validator to throw EntityValidationError instead of returning a validation response object; callers updated to catch and return HTTP 422
  • Added jsonwebtoken dependency for decoding Bearer tokens in the local dev server
  • Updated validator tests to match the new throw-based validation API

Testing

  • I have tested these changes locally
  • I have added/updated tests as needed
  • All tests pass (npm test)

Checklist

  • My code follows the project's style guidelines
  • I have performed a self-review of my own code
  • I have commented my code, particularly in hard-to-understand areas
  • I have made corresponding changes to the documentation (if applicable)
  • My changes generate no new warnings
  • I have updated docs/ (AGENTS.md) if I made architectural changes

Additional Notes

The User collection is pre-populated with the logged-in developer's info (email, name, role=admin) so that local apps behave similarly to production when reading the current user. Restricted fields (full_name, email, role) cannot be updated via the entities API, mirroring production backend constraints. The POST /User/bulk endpoint is a no-op, consistent with production behavior.


🤖 Generated by Claude | 2026-03-22 00:00 UTC

@github-actions
Copy link
Contributor

github-actions bot commented Mar 11, 2026

🚀 Package Preview Available!


Install this PR's preview build with npm:

npm i @base44-preview/cli@0.0.47-pr.406.4b9c508

Prefer not to change any import paths? Install using npm alias so your code still imports base44:

npm i "base44@npm:@base44-preview/cli@0.0.47-pr.406.4b9c508"

Or add it to your package.json dependencies:

{
  "dependencies": {
    "base44": "npm:@base44-preview/cli@0.0.47-pr.406.4b9c508"
  }
}

Preview published to npm registry — try new features instantly!

@artemdemo artemdemo changed the title Users and Authorization Users Schema Mar 16, 2026
@artemdemo artemdemo force-pushed the users-and-auth branch 2 times, most recently from 11c2912 to f7b1fa4 Compare March 17, 2026 16:06
/** @public - called by Commander internally via command dispatch */
override action(
// biome-ignore lint/suspicious/noExplicitAny: must match Commander.js action() signature
// biome-ignore lint/suspicious/noConfusingVoidType: must match Commander.js action() signature
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not related to my PR, but started to fail for me.
Ignoring

const result = validator.validate({ name: "Alice" }, schema);

expect(result.hasError).toBe(false);
expect(() => validator.validate({ name: "Alice" }, schema)).not.toThrow();
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Validator is now throwing an error, instead of returning object that describes the error.
Updating tests to handle it.
Here and below.

);
if (requiredFieldsResponse.hasError) {
return requiredFieldsResponse;
throw new EntityValidationError(requiredFieldsResponse.error);
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I found that it's more convenient to throw the error, rather than return an object that describes the error.
So I decided to refactor it a bit.

@base44 base44 deleted a comment from claude bot Mar 18, 2026
@base44 base44 deleted a comment from claude bot Mar 18, 2026
@artemdemo artemdemo changed the title Users Schema Users Entity Schema Mar 18, 2026
@artemdemo artemdemo changed the title Users Entity Schema User Entity Schema Mar 18, 2026
Comment on lines +125 to +127
private normalizeName(entityName: string): string {
return entityName.toLowerCase();
}
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Behind the scenes production is treating entity name as case-insensitive: "User" and "user" are the same.

@base44 base44 deleted a comment from claude bot Mar 18, 2026
@artemdemo artemdemo marked this pull request as ready for review March 18, 2026 12:50
@kfirstri kfirstri moved this from Backlog to In review in CLI Development Mar 18, 2026
@kfirstri kfirstri self-requested a review March 19, 2026 15:31
Copy link
Collaborator

@kfirstri kfirstri left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good, i'm not sure i understand some stuff in the entities-user-router..
Also, can we resolve the user with the auth token and not with readAuth somehow? I see we added a check to assert the api calls has a Bearer.. so maybe we can parse the token?

return;
}
logger.error(
`Error in PUT /${USER_COLLECTION}/${req.params.id}:`,
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This error looks weird, no need to use USER_COLLECTION inside the url that we're printing

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why? Can you elaborate, what is weird about it?
Can you give example of an error that you have in mind?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's probably fine for now, but i mean that it's just a coincidence that the endpoint route /users/:id has the same name as the collection, the collection name can be "users_collection", but the route will remain "users/"

@github-project-automation github-project-automation bot moved this from In review to Ready in CLI Development Mar 19, 2026
const router = createRouter({ mergeParams: true });
const parseBody = json();

function withAuth<R>(
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

love this

Copy link
Collaborator

@kfirstri kfirstri left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

noice

@github-project-automation github-project-automation bot moved this from Ready to In review in CLI Development Mar 23, 2026
@artemdemo artemdemo merged commit 09cae17 into main Mar 23, 2026
23 checks passed
@github-project-automation github-project-automation bot moved this from In review to Done in CLI Development Mar 23, 2026
@artemdemo artemdemo deleted the users-and-auth branch March 23, 2026 08:51
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

2 participants